package jdbc.test;

import cn.myschool.java79.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author oldliu
 * @since 1.0
 */
public class SelectOrderby3 {
    public static void main(String[] args) {
        int page=4;
        int pageSize=15;

        String sql = "select * from s_student order by enterdate desc limit ?,?";
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            con = DBUtil.getConnection();
            ps = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
            //设置起点
            ps.setInt(1,(page-1)*pageSize);
            ps.setInt(2,pageSize);
            rs = ps.executeQuery();

            while(rs.next()){
                System.out.print(rs.getLong("stuno") + " ");
                System.out.print(rs.getString("sname") + " ");
                System.out.print(rs.getString("qq") + " ");
                System.out.println(rs.getDate("enterdate") );
            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs,ps,con);
        }
    }
}
